package com.hsteach.enums;

import com.hsteach.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum InterestEnum {

    XLJKWT(1, "心理健康问题"),
    DQJT(2, "单亲家庭"),
    TKS(3, "特困生"),
    BCXS(4, "病残学生"),
    XWPCXS(5, "行为偏差学生"),
    ZDBH(6, "生活和学习上有重大变化"),
    XKS(7, "学困生"),
    SQZN(8, "随迁子女"),
    LSXS(9, "留守学生"),
    CZJT(10, "重组家庭"),
    ;

    private Integer code;
    private String name;

    public static List<Integer> getCodesByWord(String searchWord) {
        return Arrays.stream(InterestEnum.values())
                .filter(e -> e.getName().contains(searchWord))
                .map(InterestEnum::getCode)
                .collect(Collectors.toList());
    }

    public static String getNameByCode(Integer code) {
        InterestEnum interestEnum = Arrays.stream(InterestEnum.values())
                .filter(e -> e.getCode().equals(code))
                .findFirst().orElse(null);
        if (interestEnum == null) {
            throw new ServiceException("不存在的tag枚举：" + code);
        }
        return interestEnum.getName();
    }
}
